//#############################################################################
//#############################################################################
//This source file was written by Mert Dogar. If you have some questions about 
//the source code, please do not hesitate to ask me.
//The code is under GPL.
//Email: mertdogar@gmail.com , http://code.google.com/p/electron-cds
//#############################################################################
//#############################################################################

#include "project.h"

project::project()
{
	psheet tmp;
	tmp.name="Sheet1";
	sheets.push_back(tmp);
	active_sheet = &sheets[sheets.size()-1];
	
}
project::~project()
{
}

void project::tadd_component(Cairo::RefPtr<Cairo::Context> myContext, std::string type, vector2 pos)
{
	active_sheet->mysheet.tadd_component(myContext,type, pos);
}

cbase &project::get_component(int index)
{
	return active_sheet->mysheet.get_component(index);
}

void project::add_component(std::string type, vector2 pos)
{
	active_sheet->mysheet.add_component(type, pos);
}

void project::print_components()
{
	active_sheet->mysheet.print_components(cr);
}
void project::init(Cairo::RefPtr<Cairo::Context> myContext)
{
	cr=myContext;
}

int project::isonwho(vector2 pos)
{
	return active_sheet->mysheet.isonwho(cr,pos);
}

void project::save_project(std::string filename)
{
		// same as write_simple_doc1 but add each node
	// as early as possible into the tree.

	TiXmlDocument doc;
	TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "", "" );
	doc.LinkEndChild( decl );
	
	TiXmlElement * element = new TiXmlElement( "sheet11" );
	doc.LinkEndChild( element );
	
	TiXmlElement *celement = new TiXmlElement( "sheet");
	celement->SetAttribute("width",3000);
	celement->SetAttribute("height",3000);
	celement->SetAttribute("x",0);
	celement->SetAttribute("y",0);
	celement->SetAttribute("count",3);	
	element->LinkEndChild(celement);
	

	
	doc.SaveFile( "madeByHand2.xml" );
	
}
